package com.wwwarehouse.taskcenter.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wwwarehouse.taskcenter.R;
import com.wwwarehouse.taskcenter.bean.ChooseCarriageBean;

import java.util.ArrayList;

/**
 * @author clannad.sk
 */
public class ChooseCarriageAdapter
        extends RecyclerView.Adapter<ChooseCarriageAdapter.ChooseCarriageHolder> {


    private Context mContext;
    private ArrayList<ChooseCarriageBean.Carriage> mList;
    private int mHeight;
    private OnItemClickListener mListener;

    public ChooseCarriageAdapter(ArrayList<ChooseCarriageBean.Carriage> list, int height, Context context) {
        mContext = context;
        mList = list;
        mHeight = height;
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mListener = listener;
    }

    @Override
    public ChooseCarriageHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ChooseCarriageHolder(View.inflate(mContext, R.layout.task_center_choose_carriage_item, null));
    }

    @Override
    public void onBindViewHolder(final ChooseCarriageHolder holder, final int position) {
        final ChooseCarriageBean.Carriage dataBean = mList.get(position);
        holder.idChooseCarriageItemTv.setText(dataBean.getBrandName() != null ? dataBean.getBrandName() : "");
        holder.idChooseCarriageItemll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mListener != null){
                    mListener.itemClickListener(position, v, dataBean);
                }
            }
        });
    }

    public interface OnItemClickListener {
        void itemClickListener(int position, View view, ChooseCarriageBean.Carriage dataBean);
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class ChooseCarriageHolder extends RecyclerView.ViewHolder {

        TextView idChooseCarriageItemTv;
        LinearLayout idChooseCarriageItemll;


        ChooseCarriageHolder(View itemView) {
            super(itemView);
            idChooseCarriageItemTv = (TextView) itemView.findViewById(R.id.idChooseCarriageItemTv);
            idChooseCarriageItemll = (LinearLayout) itemView.findViewById(R.id.idChooseCarriageItemll);
        }
    }
}
